@file:Suppress("SpellCheckingInspection")

package han.cirno.corrupt.components.school.impl.mju

import han.cirno.corrupt.components.school.impl.CommonNetClient
import okhttp3.HttpUrl

object MjuEduConst {

    fun isLoopBackedToLogin(httpUrl: HttpUrl):Boolean{
        return httpUrl.host.contains("authserver.mju.edu.cn")
    }

    fun fillZero(string:String):String{
        if ((string.length and 1)==1)
            return "0$string"
        return "00$string"
    }

    fun encrypt(modulus:String, publicExponent:String, password:String):String{
        return MjuRSAUtil.encrypt(
            modulus,
            publicExponent,
            password.reversed().toByteArray(Charsets.UTF_8)
        )
    }

    sealed class Payload(
        scheme:String,
        host:String,
        path:String,
        queryPairs:Array<String>,
        postForm:Array<String>?=null,
        headers:Array<String>?=null):
        CommonNetClient.Payload(scheme, host, path, queryPairs, postForm, headers){
        companion object{
            const val FUNCTION_MODULE_CODE="gnmkdm"
        }

        data object ClassesTable: Payload(
            "https",
            "jwgl.mju.edu.cn",
            "/jwglxt/kbcx/xskbcx_cxXskbcxIndex.html",
            arrayOf(
                FUNCTION_MODULE_CODE,"N253508",
                "layout","default"),
            null,
            arrayOf("Referer","https://jwgl.mju.edu.cn/")
        )
        data class ClassTableData(val xnm:String,val xqm:String): Payload(
            "https",
            "jwgl.mju.edu.cn",
            "/jwglxt/kbcx/xskbcx_cxXsgrkb.html",
            arrayOf(FUNCTION_MODULE_CODE,"N253508"),
            arrayOf("xnm",xnm,"xqm",xqm,"kzlx","ck", "xsdm","")
        )
        data object Exam: Payload(
            "https",
            "jwgl.mju.edu.cn",
            "/jwglxt/kwgl/kscx_cxXsksxxIndex.html",
            arrayOf(FUNCTION_MODULE_CODE,"N358105","layout","default")
        )
        data class ExamData(val xnm:String,val xqm:String): Payload(
            "https",
            "jwgl.mju.edu.cn",
            "/jwglxt/kwgl/kscx_cxXsksxxIndex.html",
            arrayOf(FUNCTION_MODULE_CODE,"N358105","doType","query"),
            arrayOf(
                "xnm",xnm,"xqm",xqm,
                "ksmcdmb_id","","kch","", "kc","", "ksrq","",
                "kkbm_id","", "_search","false",
                "nd", System.currentTimeMillis().toString(),
                "queryModel.showCount","15",
                "queryModel.currentPage","1",
                "queryModel.sortName","",
                "queryModel.sortOrder","asc",
                "time","0")
        )
        data object Score:Payload(
            "https",
            "jwgl.mju.edu.cn",
            "/jwglxt/cjcx/cjcx_cxDgXscj.html",
            arrayOf(FUNCTION_MODULE_CODE,"N305005","layout","default")
        )
        data class ScoreData(val xnm:String,val xqm:String):Payload(
            "https",
            "jwgl.mju.edu.cn",
            "/jwglxt/cjcx/cjcx_cxXsgrcj.html",
            arrayOf(FUNCTION_MODULE_CODE,"N305005","doType","query"),
            arrayOf(
                "xnm",xnm,"xqm",xqm,
                "sfzgcj","",
                "kcbj","",
                "_search","false",
                "nd", System.currentTimeMillis().toString(),
                "queryModel.showCount","15",
                "queryModel.currentPage","1",
                "queryModel.sortName","",
                "queryModel.sortOrder","asc",
                "time","0")
        )
    }
}